package com.iflysse.dao;

import com.iflysse.pojo.po.common.CommonPoResp;
import com.iflysse.pojo.po.req.TeacherInfoPoReq;
import com.iflysse.pojo.po.req.UserHeadImagePoReq;
import com.iflysse.pojo.po.req.UserIdPoReq;
import com.iflysse.pojo.po.resp.TeacherPoResp;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

@Repository
public interface TeacherDao {


    /**
     * 根据账号编号查询教师信息
     * @param userIdPoReq
     * @return
     */
    @Select("select * from tb_teacher where account_id = #{accountId}")
    @Results({
            @Result(property = "teacherId",column = "teacher_id"),
            @Result(property = "nickName",column = "nick_name"),
            @Result(property = "name",column = "name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "personalSignature",column = "personal_signature"),
            @Result(property = "email",column = "email"),
            @Result(property = "headImage",column = "head_image"),
            @Result(property = "accountId",column = "account_id"),
    })
    TeacherPoResp getTeacherByAccountId(UserIdPoReq userIdPoReq)throws SQLException;

    /**
     * 根据账户编号获取老师姓名
     * @param accountId
     * @return
     */
    @Select("select name from tb_teacher where account_id = #{accountId}")
    String getTeacherNameByAccountId(String accountId) throws SQLException;

    /**
     * 根据老师编号获取老师姓名
     * @param teacherId
     * @return
     */
    @Select("select name from tb_teacher where teacher_id = #{teacherId}")
    String getTeacherNameByTeacherId(String teacherId) throws SQLException;

    /**
     * 通过老师编号,获取老师基本信息
     * @param teacherId 老师编号
     * @return
     */
    @Select("select * from tb_teacher where teacher_id = #{teacherId}")
    @Results({
            @Result(property = "teacherId",column = "teacher_id"),
            @Result(property = "nickName",column = "nick_name"),
            @Result(property = "name",column = "name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "personalSignature",column = "personal_signature"),
            @Result(property = "email",column = "email"),
            @Result(property = "headImage",column = "head_image"),
            @Result(property = "accountId",column = "account_id"),
    })
    TeacherPoResp findTeacherByTeacherId(String teacherId) throws SQLException;

    /**
     * 修改老师资料
     * @param teacherInfoPoReq
     * @return
     */
    @Update("update tb_teacher set " +
            "email=#{email} , nick_name =#{nickName},name = #{name},gender = #{gender},personal_signature = #{personalSignature} where teacher_id = #{teacherId}")
    int updateTeacher(TeacherInfoPoReq teacherInfoPoReq) throws SQLException;

    /**
     * 更新老师头像
     * @param userHeadImagePoReq
     * @return
     */
    @Update("update tb_teacher set head_image = #{headImagePath} where teacher_id = #{id}")
    int updateHeadImage4Teacher(UserHeadImagePoReq userHeadImagePoReq) throws SQLException;

    /**
     * 根据老师编号获取老师的邮箱
     * @param teacherId
     * @return
     */
    @Select("select email from tb_teacher where teacher_id = #{teacherId}")
    String getTeacherEmailByTeacherId(String teacherId) throws SQLException;

    /**
     * 根据老师编号获取老师的账户
     * @param teacherId
     * @return
     */
    @Select("select account_id from tb_teacher where teacher_id = #{teacherId}")
    String getAccountIdByTeacherId(String teacherId) throws SQLException;
}
